<script setup>

import SimpleAuthConfig from "./SimpleAuthConfig.vue";
import {onMounted, reactive} from "vue";
import {ConfigManager} from "../ConfigManager.ts";
import {AuthNMXX} from "../../wailsjs/go/main/App.js";
import {useMessage} from "naive-ui";

const message = useMessage()
const state = reactive({
  username: "",
  passwd: "",
})


function onSave() {
  console.log("onSave...")
  ConfigManager.appConfig.cfnmxx.username = state.username;
  ConfigManager.appConfig.cfnmxx.password = state.passwd;
  ConfigManager.Update();
}

function onLogin(username, passwd) {
  AuthNMXX(username, passwd).then((ret) => {
    message.success(ret.toString());
  }).catch((err) => {
    message.error(err.toString());
  })
}


onMounted(function () {
  ConfigManager.GetConfig().then((v) => {
    console.log(`getConfig... ${v.cfnmxx}`)
    state.username = v.cfnmxx.username;
    state.passwd = v.cfnmxx.password;
  })
})

</script>

<template>
  <n-flex vertical>
    <SimpleAuthConfig v-model:username="state.username" v-model:passwd="state.passwd" @save="onSave" @test="onLogin">
    </SimpleAuthConfig>
  </n-flex>
</template>

<style scoped>

</style>